package uno.rocc.controller.system;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import uno.rocc.common.util.Result;
import uno.rocc.framework.core.annotation.RoccUnoAuthorize;
import uno.rocc.framework.core.controller.BaseCURDController;
import uno.rocc.system.domain.dao.SysUser;
import uno.rocc.system.domain.dto.SysUserQueryParam;
import uno.rocc.system.domain.vo.SysUserVo;
import uno.rocc.system.service.SysUserService;

import java.util.List;

@Tag(name = "系统用户")
@Slf4j
@RestController
@RequestMapping("/sysUser")
@RoccUnoAuthorize("sysUser")
public class SysUserController extends BaseCURDController<SysUserQueryParam, SysUser, SysUserVo> {

    public SysUserController(SysUserService sysUserService) {
        super(sysUserService);
    }

    @RoccUnoAuthorize(":list")
    @Override
    public Result getList(SysUserQueryParam queryParam) {
        Result result = super.getList(queryParam);
        //转换为vo
        Page<SysUserVo> data = Page.of(1, 10);
        BeanUtil.copyProperties(result.getData(), data);
        result.setData(data);
        return result;
    }

    /**
     * 获取用户的权限
     *
     * @return
     */
    @Operation(summary = "获取用户权限")
    @RoccUnoAuthorize(":permission")
    @GetMapping("/permission")
    public Result getPermission() {
        Integer sysUserId = getSysUserId();
        List<String> permissionList = ((SysUserService) service).getPermissionAllById(sysUserId);
        return Result.success(permissionList);
    }


}
